<?php
class Ext_Form extends Zend_Form
{
	
    public function __construct($options = null)
    {
		$this->addPrefixPath('Ext_Form_Element', 'Ext/Form/Element', 'element');
        parent::__construct($options);
    }
	
    public function removeAllDecorators()
    {
    	$i = 0;
    	foreach( $this->getElements() as $e ) {
        	$e->removeDecorator( 'HtmlTag' );
        	$e->removeDecorator( 'Label' );
        	$e->removeDecorator( 'Description' );
        	$e->removeDecorator( 'DtDdWrapper' );
        	$e->removeDecorator( 'Tooltip' );
        	
        	//print_r($e);
        	//$e->clearDecorators();
        	//$i ++;
		}
		//echo $i;
    	//exit;
    }
    
    /**
     * Recive un load Node con un formato X , lo convierte para poder mostrar los datos en el formulario
     * @param $node
     */
    public function populateWithNode( $node )
    {
    	$nodeForm = $node['hdr'];

    	foreach( $node['vocabulary'] as $key => $tax ) {
    		$nodeForm['taxonomy_' . $key ] = $tax['taxonomy_id'];
    	}
    	$this->populate( $nodeForm );
    }
    
    
    /**
     * Populate form
     *
     * Proxies to {@link setDefaults()}
     * 
     * @param  mixed $values 
     * @return Zend_Form
     */
    public function populate( $values )
    {
    	$arrayResult = $values;
    	if ( $values instanceof Ext_Db_Table_Row ) {
	    		$arrayResult = array();
    			$array = $values->toArray();
    			foreach( $array as $key => $val) {
    				$arrayResult[$key] = $values->__get($key);
    		}
    	}
   		return parent::populate( $arrayResult );
    }

    /**
     * Set the view object
     *
     * Ensures that the view object has the dojo view helper path set.
     * 
     * @param  Zend_View_Interface $view 
     * @return Zend_Dojo_Form_Element_Dijit
     */
    public function setView(Zend_View_Interface $view = null)
    {
        if (null !== $view) {
            if (false === $view->getPluginLoader('helper')->getPaths('Ext_View_Helper')) {
                $view->addHelperPath('Ext/View/Helper', 'Ext_View_Helper');
            }
        }
        return parent::setView($view);
    }
	protected function addUsername()
	{
        $this->addElement('text', 'username', array(
            'label'      => 'username:',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array()
        ));
	}
	protected function addPassword()
	{
        $this->addElement('password', 'password', array(
            'label'      => 'password:',
            'required'   => true,
            'filters'    => array('StringTrim')
        ));        
	}

	protected function addDate()
	{
        $this->addElement('text', 'password', array(
            'label'      => 'password:',
            'required'   => true,
            'filters'    => array('StringTrim', 'dateDDMMYY')
        ));        
	}

	protected function addEmail()
	{
		// Add an email element
        $this->addElement('text', 'email', array(
	        'label'      => 'email:',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array( 'EmailAddress' )
        ));
	}	            
} 
